<?php
namespace api\modules\v1\controllers;

use api\components\ApiController;
use common\models\ARAssets;
use api\modules\v1\models\Assets;
use api\modules\v1\models\OrderEvaluate;
use api\modules\v1\models\UserInfo;
use Yii;
use common\models\AROrder;
use api\modules\v1\models\Order;

/**
 *
 * @author ZCY
 */
class TestController extends ApiController
{
    public function behaviors()
    {
        $behaviors = parent::behaviors();
        $behaviors['authenticator']['optional'] = ['*'];
        return $behaviors;
    }
    /**
     * 创建交易评价
     * @author ZCY
     */
    public function actionCreate()
    {
        $params = Yii::$app->request->post();
        $model = new OrderEvaluate();
        $model->setScenario(OrderEvaluate::SCENARIO_CREATE);
        $model->load($params, '');
        if ($result = $model->create()) {
            return ['message' => '评论创建成功', 'data' => $result];
        }
    }

    /**
     * 评价
     * @author ZCY
     */
    public function actionEvaluate()
    {
        $params = Yii::$app->request->post();
        $model = new OrderEvaluate();
        $model->setScenario(OrderEvaluate::SCENARIO_EVALUATE);
        $model->load($params, '');
        if ($result = $model->evaluate()) {
            return ['message' => '用户评价成功', 'data' => $result];
        }
    }

    /**
     * 评价列表
     */
    public function actionList()
    {
        $params = Yii::$app->request->post();
        $model = new OrderEvaluate();
        $model->setScenario(OrderEvaluate::SCENARIO_LIST);
        $model->load($params, '');
        if ($result = $model->evaluatelist()) {
            return ['message' => '用户评价信息获取成功', 'data' => $result];
        }
    }

    /**
     * 创建平台账户
     * @return json
     */
    public function actionCreatePlatform()
    {
        $params = Yii::$app->request->post();
        $model = new UserInfo();
        $model->setScenario(UserInfo::SCENARIO_PLATFORM);
        $model->load($params, '');
        if ($result = $model->createPlatform()) {
            return ['message' => '平台注册成功', 'data' => $result];
        }

    }

    /**
     * 添加系统权限管理员
     * @return json
     */
    public function actionAddSystemer()
    {
        $params = Yii::$app->request->post();
        $model = new UserInfo();
        $model->setScenario(UserInfo::SCENARIO_SYSTEM);
        $model->load($params, '');
        if ($result = $model->addSystemer()) {
            return ['message' => '管理员创建成功', 'data' => $result];
        }
    }

    public function actionGetAssetsecufity()
    {
        $params = Yii::$app->request->post();
        $row = ARAssets::findOne(['uid' => $params['uid'], 'coin' => $params['coin']]);
        $row->security_at = Yii::$app->formatter->asTimestamp('now');
        $row->security_code = Assets::getAssetSecufity($row);
        $row->save();
        return ['message' => '操作成功', 'data' => ['amount' => $row->amount]];
    }

    public function actionOrderCode()
    {
        $order_id = Yii::$app->request->post()['order_id'];
        $row = AROrder::findOne($order_id);
        $model = new Order();
        return ['data' => $model->getOrderSecufity($row)];
    }
    
    
    
}
